<script setup>
import { useRouter } from 'vue-router';
import Header from '../../components/Header.vue';
import titles from '../../components/titles.vue'
import { ref } from 'vue';

let router = useRouter();

let submitIdCard = () => {
    if (imageSrc.value && imageSrcs.value) {
        // console.log('提交身份证扫描件', imageSrc.value);
        // imageSrc.value = null;
        alert('身份证扫描件上传成功！');
        router.push('/chineseIDt')
        imagesUploaded.value = true;
    }
}

let imageSrc = ref(null)
let imageSrcs = ref(null)
let imagesUploaded = ref(false)
let handleFileChange = (event) => {
    let file = event.target.files[0];
    if (file && file.type.match('image.*')) {
        const reader = new FileReader();
        reader.onload = (e) => {
            imageSrc.value = e.target.result;
        };
        reader.readAsDataURL(file);
    }
}
let handleFileChanges = (event) => {
    let file = event.target.files[0];
    if (file && file.type.match('image.*')) {
        const reader = new FileReader();
        reader.onload = (e) => {
            imageSrcs.value = e.target.result;

        };
        reader.readAsDataURL(file);
    }
}

</script>



<template>
    <Header></Header>
    <div class="content">
        <titles :title="'Apply Credentials / Chinese ID'"></titles>
        <div class="box">
            <div class="left-box">
                <div>
                    <p>
                        <RouterLink to="/MyCredentials">My Credentials</RouterLink>
                    </p>
                </div>
                <div class="left-box-active">
                    <p>
                        <RouterLink to="/ApplyCredentials">Apply Credentials</RouterLink>
                    </p>
                </div>
                <div>
                    <p>
                        <RouterLink to="/AccountInformation">Account Information</RouterLink>
                    </p>
                </div>
            </div>
            <div class="right-box">
                <div class="right-box-title">
                    <p class="title">Upload Scanned copy of your Chinese ID</p>
                </div>
                <div class="right-box-id-box">
                    <div class="right-box-id">
                        <div class="file-upload-container">
                            <img v-if="!imageSrc" src="../../assets/img/Group 34437.svg" alt="默认图片"
                                class="default-image" />
                            <img v-else :src="imageSrc" alt="Image Preview" class="image-preview" />
                            <input type="file" accept="image/*" @change="handleFileChange" />
                        </div>
                        <p>Front</p>
                    </div>
                    <div class="right-box-id">
                        <div class="file-upload-container">
                            <img v-if="!imageSrcs" src="../../assets/img/Group 34438.svg" alt="默认图片"
                                class="default-image" />
                            <img v-else :src="imageSrcs" alt="Image Preview" class="image-preview" />
                            <input type="file" accept="image/*" @change="handleFileChanges" />
                        </div>
                        <p>Back</p>
                    </div>
                </div>


                <div class="right-box-bottom">
                    <!-- <button class="btn_grey">
                        <RouterLink to="/chineseIDt">Next</RouterLink>
                    </button> -->
                    <button :class="{ 'active-button': imagesUploaded }" @click="submitIdCard"
                        :disabled="!(imageSrc, imageSrcs)">Next</button>
                </div>
            </div>
        </div>
    </div>
</template>
<style scoped>
.content {
    width: 1100px;
    height: 100%;
    margin: auto;
    display: flex;
    flex-direction: column;
    margin-top: 100px;

    .title {
        display: flex;
        color: #1F2930;
        font-size: 20px;
        font-weight: 600;
        line-height: 30px;

        p {
            margin: 0 10px 20px 0;
        }

        .title-home {
            color: #0F094C;
        }
    }

    .box {
        display: flex;

        .left-box {
            display: flex;
            flex-direction: column;
            border: 1px solid #EFEFEF;
            width: 271px;
            margin: 0 20px 0 0;

            .left-box-active {
                p {
                    color: #EC535B;
                    font-weight: 700;
                    font-size: 18px;
                }

                background-color: #FFECEC;
            }

            p {
                margin: 20px 0 20px 10px;
                color: #1F2930;
                font-size: 18px;
                font-weight: 400;
            }
        }

        .right-box {
            border: 1px solid #EFEFEF;
            width: 900px;

            .right-box-title {
                margin: 20px;

            }

            .right-box-id-box {
                display: flex;
                justify-content: space-around;
            }

            .right-box-id {
                display: flex;
                flex-direction: column;
                justify-content: space-around;
                text-align: center;
                margin-top: 100px;

                .file-upload-container {
                    position: relative;

                    img {
                        width: 300px;
                        height: 198px;
                        display: block;
                        object-fit: cover;
                    }

                    .image-preview {
                        border: 1px solid #ccc;
                    }

                    .default-image {
                        cursor: pointer;
                    }

                    input[type="file"] {
                        position: absolute;
                        top: 0;
                        left: 0;
                        width: 100%;
                        height: 100%;
                        opacity: 0;
                        cursor: pointer;
                    }
                }


                p {
                    margin-top: 30px;
                    color: rgba(154, 154, 154, 0.8);
                    font-size: 16px;
                }
            }

            .right-box-bottom {
                display: flex;
                justify-content: end;

                button {
                    width: 149px;
                    height: 44px;
                    margin: 200px 50px 0 0;
                    border-radius: 6px;
                    border: none;
                    cursor: pointer;

                }

                .active-button {
                    background-color: #C7C6D3;
                    color: #ffffff;
                    
                }
            }

        }


    }
}
</style>